package com.gaobeitech.trust;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import net.minidev.json.JSONObject;

public class LoginActivity extends AppCompatActivity {

    private TextView txtLog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        txtLog = (TextView) findViewById(R.id.txtLog);

        findViewById(R.id.btnRegist).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.out.println("Register");
                startActivity(new Intent(LoginActivity.this, RegistActivity.class));
            }
        });


        findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                txtLog.setText("Clicked");



                startActivity(new Intent(LoginActivity.this, MainActivity.class));





                if (true){
                    return;
                }

                JSONObject obj = new JSONObject();
                try {
                    obj.put("loginname", "mel");
                    obj.put("password", "P@ssw0rd");

                    String postBody = obj.toJSONString();
                    HttpUtils.post("http://192.168.0.175/login", postBody, new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            System.out.println("Here is loginactivity." + msg.obj);
                            txtLog.setText(msg.obj.toString());
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });


        findViewById(R.id.btnAuTest).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HttpUtils.testAU(new Handler(){
                    @Override
                    public void handleMessage(Message msg) {
                        System.out.println(msg.obj);
                    }
                });
            }
        });

    }
}
